package com.darker.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.darker.domain.User;
import com.darker.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController
@RequestMapping("/users")
public class UserController1 {
    @Autowired
    IUserService userService;
    @GetMapping
    public List<User> getAll(){
       return userService.list();
    }
    @PostMapping
    public boolean save(@RequestBody User user){
        return userService.save(user);
    }
    @PutMapping()
    public boolean update(@RequestBody User user){
        return userService.updateById(user);
    }
    @DeleteMapping("{id}")
    public boolean delete(@PathVariable Integer id){
        return  userService.removeById(id);
    }
    @GetMapping("{id}")
    public User getById(@PathVariable Integer id){
        return userService.getById(id);
    }
    @GetMapping("{page}/{size}")
    public IPage<User> getPage(@PathVariable Integer page, @PathVariable Integer size){
        return  userService.getPage(page,size);
    }

}
